<div id="locationedDiv">
<div class="topBar">
	<p style="padding:10px 5px 0px 10px;font-size:0.9em;margin:0px;">
		<span id="domain" onclick="javascript:showDistributerList();return false;">
			<?php 
				echo $this->title;
				echo '<input type="hidden" id="distributerId" value="'.$this->distributerId.'">';
			?>
		</span>
		<a href="/address">[切换地址]</a>
	</p>
	<div id="address" onclick="javascript:showDistributerList();return false;" style="color:#999;padding:0px 0px 5px 10px;font-size:0.8em;">
		<?php 
			echo $this->subTitle;
		?>
	</div>
</div>

<div id="wrapperHome" class="wrapperComman">
<div class="scroller">
<div id="myCarousel" class="carousel slide">
   <!-- 轮播（Carousel）项目 -->
   <div class="carousel-inner">
		<?php 
		include_once(APPLICATION_PATH . '/../library/CommFun.php');
		if(!empty($this->adList)){
			foreach($this->adList as $a=>$l){
				$action = $l->action;
				$actionArr = CommFun::objectToArray($action);
				$actionStr = base64_encode(serialize($actionArr));
				echo '<div class="item" id="xiangmu'.$a.'">
						<img class="BannerImg" src="'.$l->img_url.'" alt="Second slide" actionStr="'.$actionStr.'" onclick="javascript:actionHelper(this);return false;">
					</div>';
			}
		}
		?>
   </div>
   <!-- 轮播（Carousel）导航 -->
   <?php 
		if(!empty($this->adList)){
			echo '
			<a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
			<a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
			';
			echo '
				<script type="text/javascript">
					$("#xiangmu0").addClass("active");
					$("#myCarousel").carousel({
						interval: 3000
					});
				</script>
			';
		}
   ?>
   
</div> 
<div style="padding:10px 0px;">
<?php 
if(!empty($this->hotBrandList)){
	// $w = 1/count($this->hotBrandList)*100;
	$w = 1/5*100;
	foreach($this->hotBrandList as $n=>$h){
		$action = $h->action;
		$actionArr = CommFun::objectToArray($action);
		$actionStr = base64_encode(serialize($actionArr));
		if($n<10){
			echo '
				<div hotid="'.$h->id.'" onclick="javascript:actionHelper(this);return false;" actionStr="'.$actionStr.'" style="width:'.$w.'%;float:left;text-align:center;">
					<img src="'.$h->icon.'" style="width:35px;">
					<div style="font-size:0.8em;padding:5px 0px;">'.$h->title.'</div>
				</div>
			';
			if($n==5){
				echo '<br>';
			}
		}
	}
}
?>
</div>
<div class="clear"></div>
<input id="shopidIsNull" type="hidden" value="<?php echo $this->shopidIsNull;?>">
	<?php 
		if(!empty($this->sectionList)){//&&!empty($this->distributerList)
			echo '
				<div style="width:100%;">
			';
			foreach($this->sectionList as $se){
				echo '<div class="hrCss">&nbsp;</div>';
				$icon = $se['icon'];
				echo '<div><img style="width:100%;" src="'.$icon.'"/></div>';
				$itemList = $se['itemList'];
				foreach($itemList as $k=> $item){
					$rowItem = $itemList[$k];
					echo '<div>';
					foreach($rowItem as $r){
						$action = $r['action'];
						$actionArr = CommFun::objectToArray($action);
						$actionStr = base64_encode(serialize($actionArr));
						$picon = $r['icon'];
						if(count($rowItem)==2){
							echo '<img class="secImg2" onclick="javascript:actionHelper(this);return false;" actionStr="'.$actionStr.'" style="width:50%;" src="'.$picon.'"/>';
						}
						if(count($rowItem)==3){
							echo '<img class="secImg3" onclick="javascript:actionHelper(this);return false;" actionStr="'.$actionStr.'" style="width:33%;" src="'.$picon.'"/>';
						}
						if(count($rowItem)==4){
							echo '<img class="secImg4" onclick="javascript:actionHelper(this);return false;" actionStr="'.$actionStr.'" style="width:25%;" src="'.$picon.'"/>';
						}
					}
					echo '</div>';
				}
			}
			foreach($this->presell as $p){
				// echo '<img style="width:100%;min-height:420px;" src="'.$this->presell[0]->banner.'" onclick="javascript:loadCategoryPage();return false;">';
				$shopid = $p->id;
				break;
			}
			echo '</div>';
			echo '<div style="height:60px;">&nbsp;</div>';
		}
		
		if(empty($this->adList) &&empty($this->hotBrandList) && empty($this->sectionList)){
			echo '
			<div style="text-align:center;"><img src="/images/none.jpg" style="width:50%;padding-top:110px;"></div>
			<div style="padding:10px;text-align:center;">
					亲，该地区暂未开通哦，<a href="/address">[切换地址]</a>看看</div>';
		}
	?>
</div>
</div>


<?php 
if(!empty($this->distributerList)){
	echo'
	<div class="distributerCss" id="distributerList" style="display:none">
		<p style="padding-top:10px;text-align:center;">'.$this->domain.'</p>
		<p style="text-align:center;border-bottom:1px solid #E6E6E6;">(请选择您方便的自提点)</p>';
		
		foreach($this->distributerList as $n=>$d){
			echo '<div class="disList" id="disList'.$n.'" distributerId='.$d->id.' sitename='.str_replace(" ","",$d->sitename).' address='.str_replace(" ","",$d->address).' onclick="javascript:changeDistributer(this);return false;" style="padding:5px 10px;border-bottom:1px solid #E6E6E6;">
				<p style="float:left;width:80%;">'.$d->sitename.'</p>
				<p style="float:right;width:19%;text-align:center;font-size:0.8em;">距离</p>
				<div class="clear"></div>
				<p style="float:left;width:80%;font-size:0.9em;">'.$d->address.'</p>
				<p style="float:right;width:19%;text-align:center;color:red;">';
				if(substr($d->distance,0,4)>1){
					echo substr($d->distance,0,4);
				}else{
					echo substr($d->distance,0,4)*1000;
				}
				echo '<span style="font-size:0.8em;color:grey;">';
				if(substr($d->distance,0,4)>1){
					echo '公里';
				}else{
					echo '米';
				}
				echo '</span></p>
				<div class="clear"></div>
			</div>';
		}
	echo '
	</div>';
	echo '
		<script type="text/javascript">
			var hiddenDistuibuterId = $("#distributerId").val();
			if(isNull(hiddenDistuibuterId)){
				$("#disList0").css("color","green");
			}else{
				var len = $(".disList").length;
				for(var i=0;i<len;i++){
					var distributerId = $("#disList"+i).attr("distributerId");
					if(hiddenDistuibuterId == distributerId){
						$("#disList"+i).css("color","green");
					}
				}
			}
			$("body").append("<div id=\"masktg\" class=\"mask\" onclick=\"javascript:hiddenFuCeng();return false;\"></div>");
			$("#masktg").addClass("mask").fadeOut("slow");
		</script>
	';
}
if(true == $this->needUpdateDistributer){
  echo '<script type="text/javascript">$("#distributerList").show();$("#masktg").show();</script>';
}

?>
</div>

<div id="loadingAnimation" style="display:none;width:100%;text-align:center;padding-top:150px;">
<img style="width:50%;" src="/images/loading2.gif"/>
</div>

<div id="locatingImg" style="width:100%;margin:0px;display:none;text-align:center;">
	<div class="topRight">&nbsp;</div>
	<div class="topContent">鲜店</div>
	<div class="topRight">&nbsp;</div>
	<div class="clear"></div>
	<img src="/images/locating.gif" style="width:70%;margin-top:40%;">
</div>
<input type="hidden" id="needAutoLocation" value="<?php echo $this->needAutoLocate;?>">
<script type="text/javascript">
	$(document).ready(function() {
		 var deviceWidth = document.body.clientWidth;
		 var bannerImgHeight = deviceWidth*240/640;
		 $('.BannerImg').css('height',bannerImgHeight+'px');
		 $('.BannerImg').css('max-height',240+'px');
		 var img2Height = deviceWidth/2*246/375;
		 $('.secImg2').css('height',img2Height+'px');
		  var img3Height = deviceWidth/3*264/250;
		 $('.secImg3').css('height',img3Height+'px');
		  var img4Height = deviceWidth/4*225/187;
		 $('.secImg4').css('height',img4Height+'px');
		 
		 
		 var needLocate = $('#needAutoLocation').val();
		if(needLocate == 'no'){
			$('#locatingImg').hide();
		} else {
			var winHeight = getWinHeight();
			$('#locationedDiv').hide();
			$('.index_bottom').hide();
			$('#locatingImg').show();
			$('#locatingImg').css('height',winHeight);

			if(navigator.geolocation){
				navigator.geolocation.getCurrentPosition(locateSuccessHandler,
														locateFailedHandler,
														{enableHighAccuracy:true,
														 maximumAge:1000,
														 timeout:8000
														});
			}else{
				alert("您的微信浏览器不支持定位");
			}
		}
		
		
		var top = $('.topBar').css('height');
		$('.wrapperComman').css('top',top);
		var myScroll;
		function loaded(){
           setTimeout(function(){
                    myscroll=new iScroll("wrapperHome");
             },100 );
        }
		loaded();
	});
	
</script>
